package com.alibaba.nacos.plugin.datasource.impl.kingbase8;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.alibaba.nacos.plugin.datasource.constants.DefaultConstant.DEFAULT_TENANT_ID;

public class ConfigInfoMapperByKingbase8 extends AbstractKingbase8Mapper implements ConfigInfoMapper {

    @Override
    public MapperResult findConfigMaxId(MapperContext context) {

      String sql="SELECT MAX(id) FROM config_info";
      return new MapperResult(sql, CollectionUtils.list(new Object[0]));
    }

    @Override
    public MapperResult findAllDataIdAndGroup(MapperContext context) {

        String sql="SELECT DISTINCT data_id, group_id FROM config_info";
        return new MapperResult(sql, CollectionUtils.list(new Object[0]));
    }

    @Override
    public MapperResult findConfigInfoByAppCountRows(MapperContext context) {


        String appName = (String)context.getWhereParameter(FieldConstant.APP_NAME);
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);

        List<Object> paramList = new ArrayList();


        String where = " 1=1 ";


        if (!StringUtils.isBlank(appName)) {
            where += " AND app_name = ? ";
            paramList.add(appName);
        }
        paramList.add(tenantId);
        String sql="SELECT count(*) FROM config_info WHERE "+where +"AND tenant_id = NVL(?,'\" + DEFAULT_TENANT_ID + \"') ";

        return new MapperResult(sql, paramList);
    }

    @Override
    public MapperResult findConfigInfoByAppFetchRows(MapperContext context) {
        String tenantId = (String)context.getWhereParameter("tenantId");
        String appName = (String)context.getWhereParameter("appName");
        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        List<Object> paramList = new ArrayList();
        paramList.add(tenantId);
        paramList.add(appName);
        String sqlInner = "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info"
                + " WHERE tenant_id LIKE NVL(?,'" + DEFAULT_TENANT_ID + "') AND app_name= ?";
        String sql=getDatabaseDialect().getLimitPageSqlWithOffset(sqlInner, startRow, pageSize);
        return new MapperResult(sql, paramList);
    }

    @Override
    public MapperResult configInfoLikeTenantCount(MapperContext context) {

        String tenantId = (String)context.getWhereParameter("tenant");
        String where = " 1=1 ";
        List<Object> paramList = new ArrayList();
        if (!StringUtils.isBlank(tenantId)) {
            where += " AND tenant_id = ? ";
            paramList.add(tenantId);
        }

        String sql="SELECT count(*) FROM config_info  WHERE " + where;
        return new MapperResult(sql, paramList);
    }

    @Override
    public MapperResult getTenantIdList(MapperContext context) {
        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        String sql=getDatabaseDialect().getLimitPageSqlWithOffset(
                "SELECT tenant_id FROM config_info WHERE tenant_id != '"
                        + DEFAULT_TENANT_ID + "' GROUP BY tenant_id ",
                startRow, pageSize);
        return new MapperResult(sql, CollectionUtils.list(new Object[0]));
    }

    @Override
    public MapperResult getGroupIdList(MapperContext context) {
        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        String sql=getDatabaseDialect().getLimitPageSqlWithOffset(
                "SELECT group_id FROM config_info WHERE tenant_id != '"
                        + DEFAULT_TENANT_ID + "' GROUP BY group_id ",
                +startRow, pageSize);
        return new MapperResult(sql, CollectionUtils.list(new Object[0]));
    }

    @Override
    public MapperResult findAllConfigKey(MapperContext context) {
        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        String tenantId = (String)context.getWhereParameter("tenant");
        List<Object> paramList = new ArrayList();
        paramList.add(tenantId);
        String innerSql = getDatabaseDialect().getLimitPageSqlWithOffset(" SELECT id FROM config_info WHERE tenant_id LIKE NVL(?,'"
                + DEFAULT_TENANT_ID
                + "') ORDER BY id", startRow, pageSize);
        String sql=" SELECT data_id,group_id,app_name  FROM ( " + innerSql + " )" + " g, config_info t WHERE g.id = t.id  ";
        return new MapperResult(sql, paramList);
    }

    @Override
    public MapperResult findAllConfigInfoBaseFetchRows(MapperContext context) {
        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        String innerSql = getDatabaseDialect().getLimitPageSqlWithOffset(
                " SELECT id FROM config_info ORDER BY id ", startRow, pageSize);
        String sql=" SELECT t.id,data_id,group_id,content,md5" + " FROM ( " + innerSql + "  ) " + " g, config_info t  WHERE g.id = t.id ";

        return new MapperResult(sql, CollectionUtils.list(new Object[0]));
    }

    @Override
    public MapperResult findAllConfigInfoFragment(MapperContext context) {

        String sql= "SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key "
                        + "FROM config_info ORDER BY id ASC ";
        return new MapperResult(sql, CollectionUtils.list(new Object[0]));
    }

    @Override
    public MapperResult findChangeConfig(MapperContext context) {
        Timestamp startTime = (Timestamp)context.getWhereParameter("startTime");
        List<Object> paramList = new ArrayList();
        paramList.add(startTime);
        String sql= "SELECT data_id, group_id, tenant_id, app_name, content, gmt_modified,encrypted_data_key "
                + "FROM config_info WHERE gmt_modified >= ? AND gmt_modified <= ?";
        return new MapperResult(sql, paramList);
    }

    @Override
    public MapperResult findChangeConfigCountRows(MapperContext context) {

        String appName = (String)context.getWhereParameter(FieldConstant.APP_NAME);
        String dataId = (String)context.getWhereParameter(FieldConstant.DATA_ID);
        String group = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);
        Timestamp startTime = (Timestamp)context.getWhereParameter("startTime");
        Timestamp endTime = (Timestamp)context.getWhereParameter("endTime");
        List<Object> paramList = new ArrayList();

        paramList.add(tenantId);
        String where = " 1=1 and tenant_id LIKE NVL(?,'\"\n" +
                "                + DEFAULT_TENANT_ID\n" +
                "                + \"')";
        if (!StringUtils.isBlank(dataId)) {
            where += " AND data_id LIKE ? ";
            paramList.add(dataId);
        }
        if (!StringUtils.isBlank(group)) {
            where += " AND group_id LIKE ? ";
            paramList.add(group);
        }


        if (!StringUtils.isBlank(appName)) {
            where += " AND app_name = ? ";
            paramList.add(appName);
        }
        if (startTime != null) {
            where += " AND gmt_modified >=? ";
            paramList.add(startTime);
        }
        if (endTime != null) {
            where += " AND gmt_modified <=? ";
            paramList.add(endTime);
        }
        return new MapperResult("SELECT count(*) FROM config_info WHERE " + where, paramList);
    }

    @Override
    public MapperResult findChangeConfigFetchRows(MapperContext context) {

        String appName = (String)context.getWhereParameter(FieldConstant.APP_NAME);
        String dataId = (String)context.getWhereParameter(FieldConstant.DATA_ID);
        String group = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);

        Timestamp startTime = (Timestamp)context.getWhereParameter("startTime");
        Timestamp endTime = (Timestamp)context.getWhereParameter("endTime");

        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        long lastMaxId = (long)context.getWhereParameter("lastMaxId");
        List<Object> paramList = new ArrayList();
        final String tenantTmp = StringUtils.isBlank(tenantId) ? StringUtils.EMPTY : tenantId;
        final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified FROM config_info WHERE ";
        String where = " 1=1 ";
        if (!StringUtils.isBlank(dataId)) {
            where += " AND data_id LIKE ? ";
            paramList.add(dataId);
        }
        if (!StringUtils.isBlank(group)) {
            where += " AND group_id LIKE ? ";
            paramList.add(group);
        }

        if (!StringUtils.isBlank(tenantTmp)) {
            where += " AND tenant_id = ? ";
            paramList.add(tenantTmp);
        }

        if (!StringUtils.isBlank(appName)) {
            where += " AND app_name = ? ";
            paramList.add(appName);
        }
        if (startTime != null) {
            where += " AND gmt_modified >=? ";
            paramList.add(startTime);
        }
        if (endTime != null) {
            where += " AND gmt_modified <=? ";
            paramList.add(endTime);
        }
        String originSql = sqlFetchRows + where + " AND id > " + lastMaxId
                + " ORDER BY id ASC";
        return new MapperResult(getDatabaseDialect().getLimitPageSqlWithOffset(originSql, startRow, pageSize), paramList);
    }

    @Override
    public MapperResult listGroupKeyMd5ByPageFetchRows(MapperContext context) {
        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        String innerSql = getDatabaseDialect().getLimitPageSqlWithOffset(
                " SELECT id FROM config_info ORDER BY id ", startRow, pageSize);
        return new MapperResult(" SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM "
                + "( " + innerSql + " ) g, config_info t WHERE g.id = t.id",CollectionUtils.list(new Object[0]));
    }

    @Override
    public MapperResult findAllConfigInfo4Export(MapperContext context) {
        List<Long> ids = (List)context.getWhereParameter("ids");
        String appName = (String)context.getWhereParameter(FieldConstant.APP_NAME);
        String dataId = (String)context.getWhereParameter(FieldConstant.DATA_ID);
        String group = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);
        String tenantTmp = StringUtils.isBlank(tenantId) ? StringUtils.EMPTY : tenantId;
        String sql =
                "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,src_ip,"
                        + "c_desc,c_use,effect,c_schema,encrypted_data_key FROM config_info";
        StringBuilder where = new StringBuilder(" WHERE 1=1 ");
        List<Object> paramList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(ids)) {
            where.append(" AND  id IN (");
            for (int i = 0; i < ids.size(); i++) {
                if (i != 0) {
                    where.append(", ");
                }
                where.append('?');
                paramList.add(ids.get(i));
            }
            where.append(") ");
        } else {
            where.append(" AND tenant_id=NVL(?, '").append(DEFAULT_TENANT_ID).append("') ");
            paramList.add(tenantTmp);

            if (!StringUtils.isBlank(dataId)) {
                where.append(" AND data_id LIKE ? ");
                paramList.add(dataId);
            }
            if (StringUtils.isNotBlank(group)) {
                where.append(" AND group_id= ? ");
                paramList.add(group);
            }
            if (StringUtils.isNotBlank(appName)) {
                where.append(" AND app_name= ? ");
                paramList.add(appName);
            }
        }
        return new MapperResult(sql + where, paramList);
    }


    @Override
    public MapperResult findConfigInfoBaseLikeCountRows(MapperContext context) {
        String dataId = (String)context.getWhereParameter(FieldConstant.DATA_ID);
        String group = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);
        String content = (String)context.getWhereParameter(FieldConstant.CONTENT);
        final String sqlCountRows = "SELECT count(*) FROM config_info ";
        List<Object> paramList = new ArrayList<>();
        tenantId=StringUtils.isBlank(tenantId)?DEFAULT_TENANT_ID:tenantId;
        String where = " 1=1  ";
        if (!StringUtils.isBlank(tenantId)){
            where += " AND tenant_id LIKE ? ";
            paramList.add(tenantId);
        }
        if (!StringUtils.isBlank(dataId)){
            where += " AND data_id LIKE ? ";
            paramList.add(dataId);
        }
        if (!StringUtils.isBlank(group)) {
            where += " AND group_id LIKE ";
            paramList.add(group);
        }
        if (!StringUtils.isBlank(content)) {
            where += " AND content LIKE ? ";
            paramList.add(content);
        }
        return new MapperResult(sqlCountRows + where, paramList);
    }

    @Override
    public MapperResult findConfigInfoBaseLikeFetchRows(MapperContext context) {
        String appName = (String)context.getWhereParameter(FieldConstant.APP_NAME);
        String dataId = (String)context.getWhereParameter(FieldConstant.DATA_ID);
        String group = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);
        String content = (String)context.getWhereParameter(FieldConstant.CONTENT);
        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE ";
        String where = " 1=1  ";
        tenantId=StringUtils.isBlank(tenantId)?DEFAULT_TENANT_ID:tenantId;
        List<Object> paramList = new ArrayList<>();
        if (!StringUtils.isBlank(tenantId)){
            where += " AND tenant_id LIKE ? ";
            paramList.add(tenantId);
        }
        if (!StringUtils.isBlank(dataId)){
            where += " AND data_id LIKE ? ";
            paramList.add(dataId);
        }
        if (!StringUtils.isBlank(appName)){
            where += " AND app_name LIKE ? ";
            paramList.add(appName);
        }
        if (!StringUtils.isBlank(group)) {
            where += " AND group_id LIKE ";
            paramList.add(group);
        }
        if (!StringUtils.isBlank(content)) {
            where += " AND content LIKE ? ";
            paramList.add(content);
        }

        return new MapperResult(getDatabaseDialect().getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize), paramList);
    }

    @Override
    public MapperResult findConfigInfo4PageCountRows(MapperContext context) {
        String appName = (String)context.getWhereParameter(FieldConstant.APP_NAME);
        String dataId = (String)context.getWhereParameter(FieldConstant.DATA_ID);
        String group = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);

        List<Object> paramList = new ArrayList<>();
        final String sqlCount = "SELECT count(*) FROM config_info";
        StringBuilder where = new StringBuilder(" WHERE 1=1 ");
        tenantId=StringUtils.isBlank(tenantId)?DEFAULT_TENANT_ID:tenantId;

        if (StringUtils.isNotBlank(tenantId)) {
            where.append(" AND tenant_id=? ");
            paramList.add(tenantId);
        }
        if (StringUtils.isNotBlank(dataId)) {
            where.append(" AND data_id=? ");
            paramList.add(dataId);
        }
        if (StringUtils.isNotBlank(group)) {
            where.append(" AND group_id=? ");
            paramList.add(group);
        }
        if (StringUtils.isNotBlank(appName)) {
            where.append(" AND app_name=? ");
            paramList.add(appName);
        }
        return new MapperResult(sqlCount + where, paramList);
    }

    @Override
    public MapperResult findConfigInfo4PageFetchRows(MapperContext context) {
        String appName = (String)context.getWhereParameter(FieldConstant.APP_NAME);
        String dataId = (String)context.getWhereParameter(FieldConstant.DATA_ID);
        String group = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);
        List<Object> paramList = new ArrayList<>();
        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info";
        StringBuilder where = new StringBuilder(" WHERE 1=1");
        tenantId=StringUtils.isBlank(tenantId)?DEFAULT_TENANT_ID:tenantId;
        if (!StringUtils.isBlank(tenantId)) {
            where.append(" AND tenant_id=?");
            paramList.add(tenantId);
        }
        if (StringUtils.isNotBlank(dataId)) {
            where.append(" AND data_id=? ");
            paramList.add(dataId);
        }
        if (StringUtils.isNotBlank(group)) {
            where.append(" AND group_id=? ");
            paramList.add(group);
        }
        if (StringUtils.isNotBlank(appName)) {
            where.append(" AND app_name=? ");
            paramList.add(appName);
        }
        return new MapperResult(getDatabaseDialect().getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize), paramList);
    }

    @Override
    public MapperResult findConfigInfoBaseByGroupFetchRows(MapperContext context) {
        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        List<Object> paramList = new ArrayList<>();
        String group = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        paramList.add(group);
        String tenantId = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        tenantId=StringUtils.isBlank(tenantId)?DEFAULT_TENANT_ID:tenantId;
        paramList.add(tenantId);
        String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? and "
                + " tenant_id=NVL(?, '" + DEFAULT_TENANT_ID + "') ";
        return new MapperResult(getDatabaseDialect().getLimitPageSqlWithOffset(sql, startRow, pageSize), paramList);

    }

    @Override
    public MapperResult findConfigInfoLike4PageCountRows(MapperContext context) {
        String appName = (String)context.getWhereParameter(FieldConstant.APP_NAME);
        String dataId = (String)context.getWhereParameter(FieldConstant.DATA_ID);
        String group = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);
        String content = (String)context.getWhereParameter(FieldConstant.CONTENT);
        List<Object> paramList = new ArrayList<>();

        final String sqlCountRows = "SELECT count(*) FROM config_info";
        StringBuilder where = new StringBuilder(" WHERE 1=1 ");
        tenantId=StringUtils.isBlank(tenantId)?DEFAULT_TENANT_ID:tenantId;
        if (!StringUtils.isBlank(tenantId)) {
            where.append(" AND tenant_id LIKE ? ");
            paramList.add(tenantId);
        }
        if (!StringUtils.isBlank(dataId)) {
            where.append(" AND data_id LIKE ? ");
            paramList.add(dataId);
        }
        if (!StringUtils.isBlank(group)) {
            where.append(" AND group_id LIKE ? ");
            paramList.add(group);
        }
        if (!StringUtils.isBlank(appName)) {
            where.append(" AND app_name = ? ");
            paramList.add(appName);
        }
        if (!StringUtils.isBlank(content)) {
            where.append(" AND content LIKE ? ");
            paramList.add(content);
        }
        return new MapperResult(sqlCountRows + where, paramList);
    }

    @Override
    public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {
        String appName = (String)context.getWhereParameter(FieldConstant.APP_NAME);
        String dataId = (String)context.getWhereParameter(FieldConstant.DATA_ID);
        String group = (String)context.getWhereParameter(FieldConstant.GROUP_ID);
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);
        String content = (String)context.getWhereParameter(FieldConstant.CONTENT);
        List<Object> paramList = new ArrayList<>();
        int startRow = context.getStartRow();
        int pageSize = context.getPageSize();
        final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info";
        StringBuilder where = new StringBuilder(" WHERE 1=1 ");
        tenantId=StringUtils.isBlank(tenantId)?DEFAULT_TENANT_ID:tenantId;
        if (!StringUtils.isBlank(tenantId)) {
            where.append(" AND tenant_id=? ");
            paramList.add(tenantId);
        }
        if (!StringUtils.isBlank(dataId)) {
            where.append(" AND data_id LIKE ? ");
            paramList.add(dataId);
        }
        if (!StringUtils.isBlank(group)) {
            where.append(" AND group_id LIKE ? ");
            paramList.add(group);
        }
        if (!StringUtils.isBlank(appName)) {
            where.append(" AND app_name LIKE ? ");
            paramList.add(appName);
        }
        if (!StringUtils.isBlank(content)) {
            where.append(" AND content LIKE ? ");
            paramList.add(content);
        }
        return new MapperResult(getDatabaseDialect().getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize), paramList);
    }

    @Override
    public MapperResult findAllConfigInfoFetchRows(MapperContext context) {
        String tenantId = (String)context.getWhereParameter(FieldConstant.TENANT_ID);
        List<Object> paramList = new ArrayList<>();
        paramList.add(tenantId);
        String innerSql = getDatabaseDialect().getLimitPageSqlWithMark("SELECT id FROM config_info WHERE tenant_id LIKE NVL(?,'" + DEFAULT_TENANT_ID + "') ORDER BY id");
        return new MapperResult(" SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 "
                + " FROM ( " + innerSql + " )" + " g, config_info t  WHERE g.id = t.id ",paramList);
    }

    @Override
    public MapperResult findConfigInfosByIds(MapperContext context) {
        List<Long> ids = (List)context.getWhereParameter(FieldConstant.IDS);

        ArrayList<Object> paramList = new ArrayList();
        StringBuilder sql = new StringBuilder(
                "SELECT ID,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE ");
        sql.append("id IN (");
        for (int i = 0; i < ids.size(); i++) {
            if (i != 0) {
                sql.append(", ");
            }
            sql.append('?');
            paramList.add(ids.get(i));
        }
        sql.append(") ");
        return new MapperResult(sql.toString(),paramList);
    }

    @Override
    public MapperResult removeConfigInfoByIdsAtomic(MapperContext context) {
        List<Long> ids = (List)context.getWhereParameter(FieldConstant.IDS);
        ArrayList<Object> paramList = new ArrayList();
        StringBuilder sql = new StringBuilder("DELETE FROM config_info WHERE ");
        sql.append("id IN (");
        for (int i = 0; i < ids.size(); i++) {
            if (i != 0) {
                sql.append(", ");
            }
            sql.append('?');
            paramList.add(ids.get(i));
        }
        sql.append(") ");
        return new MapperResult(sql.toString(),paramList);
    }

    @Override
    public String getTableName() {
        return TableConstant.CONFIG_INFO;
    }

    @Override
    public MapperResult updateConfigInfoAtomicCas(MapperContext context) {
        List<Object> paramList = new ArrayList();
        paramList.add(context.getUpdateParameter(FieldConstant.CONTENT));
        paramList.add(context.getUpdateParameter(FieldConstant.MD5));

        paramList.add(context.getUpdateParameter(FieldConstant.SRC_IP));
        paramList.add(context.getUpdateParameter(FieldConstant.SRC_USER));
        paramList.add(context.getUpdateParameter(FieldConstant.GMT_MODIFIED));
        paramList.add(context.getUpdateParameter(FieldConstant.APP_NAME));
        paramList.add(context.getUpdateParameter(FieldConstant.C_DESC));
        paramList.add(context.getUpdateParameter(FieldConstant.C_USE));
        paramList.add(context.getUpdateParameter(FieldConstant.EFFECT));
        paramList.add(context.getUpdateParameter(FieldConstant.TYPE));
        paramList.add(context.getUpdateParameter(FieldConstant.C_SCHEMA));
        paramList.add(context.getWhereParameter(FieldConstant.DATA_ID));
        paramList.add(context.getWhereParameter(FieldConstant.GROUP_ID));
        paramList.add(context.getWhereParameter(FieldConstant.TENANT_ID));


       String sql="UPDATE config_info SET "
                + "content=?, md5 = ?, src_ip=?,src_user=?,gmt_modified=?, app_name=?,c_desc=?,c_use=?,effect=?,type=?,c_schema=? "
                + "WHERE data_id=? AND group_id=? " + " AND tenant_id=NVL(?, '"
                + DEFAULT_TENANT_ID + "') ";

        return new MapperResult(sql, paramList);
    }
    @Override
    public String getFunction(String s) {
        return s;
    }


}
